<?php


namespace app\system\controller;

class Menu extends AdminBase
{
	public function getlist()
	{
		$result = \app\system\service\MenuService::getlist();
		$this->response($result["code"], "获取成功", $result["data"]);
	}
	public function getinfo($id)
	{
		$options = ["id" => $id];
		$result = \app\system\service\MenuService::getinfo($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function choose($id = "", $isall = false)
	{
		$options = ["id" => $id, "isall" => $isall];
		$result = \app\system\service\MenuService::choose($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function add()
	{
		$options = $this->request->post();
		$result = $this->validate($options, "app\\system\\validate\\Menu");
		if ($result !== true) {
			$this->response(\app\system\model\Code::fail, $result);
		}
		$result = \app\system\service\MenuService::add($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "添加成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function edit()
	{
		$options = $this->request->post();
		$result = $this->validate($options, "app\\system\\validate\\Menu");
		if ($result !== true) {
			$this->response(\app\system\model\Code::fail, $result);
		}
		$result = \app\system\service\MenuService::edit($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "编辑成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function status()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["id" => "require", "disable" => "require"], ["id.require" => "id不能为空", "disable.require" => "disable 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\MenuService::status($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "设置成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function show()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["id" => "require", "show" => "require"], ["id.require" => "id不能为空", "show.require" => "show 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\MenuService::show($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "设置成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function del()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["ids" => "require"], ["ids.require" => "ids不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\MenuService::status($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "删除成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
}